package ri;
import rn.DniException;  
import rn.NombreFormatoException;
import rn.EdadFormatoException;
import rn.SqlAPI;

import java.sql.SQLException;

public class TextoUI {
	public static void main(String[] args) throws DniException, SQLException {		
		SqlAPI queryExecutor = new SqlAPI();
		if (args[0].equals("c")) {
			try {
				queryExecutor.insertar(args[1], args[2], Integer.parseInt(args[3]));
			} catch (NombreFormatoException e) {
				e.printStackTrace();
			} catch (EdadFormatoException e) {
				e.printStackTrace();
			} catch (SQLException e) {
				e.printStackTrace();				
			}
		}
		else if (args[0].equals("r")) {
			try {
				System.out.println(queryExecutor.getNom(args[1]) + "  :  " + queryExecutor.getEdad(args[1]));
			} catch (DniException e) {
				e.printStackTrace();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		else if (args[0].equals("u")) {
			if (args[2].equals("edad")) {
				try {
					queryExecutor.modificarEdad(args[1], Integer.parseInt(args[3]));
				} catch(DniException e) {
					e.printStackTrace();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
			if (args[2].equals("nom")) {
				try {
					queryExecutor.modificarNombre(args[1], args[3]);
				} catch(DniException e) {
					e.printStackTrace();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}	
		}
		else if (args[0].equals("d")) {
			try {
				queryExecutor.borrar(args[1]);
			} catch (DniException e) {
				e.printStackTrace();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		queryExecutor.commit();
		queryExecutor.cerrarConexion();
	}
}
